package com.main.common.configs;

import com.main.common.filters.GatewayPermissionFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class GatewayFilterConfig {

//    @Bean
//    public FilterRegistrationBean<GatewayPermissionFilter> filterRegistration() {
//        FilterRegistrationBean<GatewayPermissionFilter> registration = new FilterRegistrationBean<GatewayPermissionFilter>();
//        registration.setFilter(new GatewayPermissionFilter());
//        registration.addUrlPatterns("/api"); // 设置过滤器作用的URL路径
//        registration.setOrder(1);
//        registration.setName("GatewayPermissionFilter");
//        return registration;
//    }

    //注册网关过滤器
    @Bean
    public FilterRegistrationBean<GatewayPermissionFilter> registrationBean(){
        FilterRegistrationBean<GatewayPermissionFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new GatewayPermissionFilter());
        filterRegistrationBean.addUrlPatterns("/*");
//        filterRegistrationBean.addUrlPatterns("/login/*");
//        无效
//        filterRegistrationBean.addUrlPatterns("/api/*");
//        多个过滤器时执行顺序
        filterRegistrationBean.setOrder(2);
        filterRegistrationBean.setName("GatewayPermissionFilter");
        return filterRegistrationBean;
    }

}
